﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.AddIn.Pipeline;
using System.AddIn.Contract;
using RootfusAddinView;
using System.Windows;
using RootfusAddinContracts;

namespace RootfusAddinAddinSideAdapters
{
    /// <summary>
    /// Maps the addin's surface item over to the contract.
    /// </summary>
    [AddInAdapter]
    public class RootfusSurfaceItemViewtoContractAdapter : ContractBase, IRootfusSurfaceItemContract
    {
        private RootfusSurfaceItem _view;

        /// <summary>
        /// Setup and remember who our view is...
        /// </summary>
        /// <param name="view"></param>
        public RootfusSurfaceItemViewtoContractAdapter (RootfusSurfaceItem view)
        {
            _view = view;
        }

        #region IRootfusSurfaceItemContract Members

        public IListContract<IPinDefinitionContract> InputPins
        {
            get
            {
                return CollectionAdapters.ToIListContract<PinDefinition, IPinDefinitionContract>(
                    _view.InputPins,
                    PinDefinitionHostAdapters.ViewToContract,
                    PinDefinitionHostAdapters.ContractToView);
            }
        }

        public IListContract<string> OutputPinNames
        {
            get
            {
                return CollectionAdapters.ToIListContract<string>(_view.OutputPinNames);
            }
        }

        /// <summary>
        /// Called to request the add-in update itself.
        /// </summary>
        public void Update()
        {
            _view.Update();
        }

        public void SetCallback(ISICallbackContract callback)
        {
            _view.SetCallback(new SICallbackContractToView(callback));
        }

        public RootfusAddinContracts.ROOTObjectSpec GetPinDataAsROOTObject(string pinname)
        {
            return UtilityConverters.ConvertROOTObjectSpec(_view.GetPinDataAsROOTObject(pinname));
        }
        public INativeHandleContract SurfaceUI
        {
            get { return FrameworkElementAdapters.ViewToContractAdapter(_view.SurfaceUI); }
        }

        public INativeHandleContract ConfigUI
        {
            get { return FrameworkElementAdapters.ViewToContractAdapter(_view.ConfigUI); }
        }

        public bool HasSettingsUI
        {
            get { return _view.HasSettingsUI; }
        }

        public void ConfigDone()
        {
            _view.ConfigDone();
        }

        public void SetConfigXML(string xml_config)
        {
            _view.SetConfigXML(xml_config);
        }

        public bool SurfaceUIResizeAllowed
        {
            get { return _view.SurfaceUIResizeAllowed; }
        }

        public void RequestResize(double width, double height)
        {
            _view.RequestResize(width, height);
        }

        #endregion
    }
}
